//
//  RootTabBarController.m
//  WeCommunity
//
//  Created by mac on 2017/6/14.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "RootTabBarController.h"

@interface RootTabBarController ()<UITabBarControllerDelegate>

@end

@implementation RootTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.delegate = self;

}


- (void)addChildViewController:(UIViewController *)childController
                         title:(NSString *)title
               showTabBarTitle:(BOOL)showTitle
                         image:(UIImage *)image
                 selectedImage:(UIImage *)selectedImage

{
    
    
    RootNaviViewController *nav = [[RootNaviViewController alloc] initWithRootViewController:childController];
    nav.navigationBar.translucent = NO;//设置不透明
    nav.navigationBar.barTintColor = NAVC_COLOR; //导航条颜色
    nav.navigationBar.tintColor = WHITE_COLOR;  //导航条字体颜色

    
//    [nav.tabBarItem setImage:image];
//    [nav.tabBarItem setSelectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
//    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:TINT_GREEN_COLOR} forState:UIControlStateSelected];
    
    UITabBarItem * tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image selectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:TINT_GREEN_COLOR} forState:UIControlStateSelected];
    childController.tabBarItem = tabBarItem;
    
    if (showTitle && title.length > 0) {
        childController.title = title;
    }else if (!showTitle && title.length > 0) {
        // 设置图片居中, 这儿需要注意top和bottom必须绝对值一样大
        childController.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
        childController.tabBarItem.title = nil;
        
        UILabel *titleText = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 120, 44)];
        titleText.textColor=WHITE_COLOR;
        [titleText setFont:PFM_FONT(17)];
        titleText.textAlignment = NSTextAlignmentCenter;
        [titleText setText:title];
        childController.navigationItem.titleView = titleText;
        
    }else if (title.length == 0){
        // 设置图片居中, 这儿需要注意top和bottom必须绝对值一样大
        childController.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
        childController.tabBarItem.title = nil;
    }
    [self addChildViewController:nav];
}


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    
    return YES;
}




@end
